package com.baseweb.webadmin.controller.admin;


import com.baseweb.webadmin.controller.BaseController;
import com.baseweb.webadmin.core.constants.*;
import com.baseweb.webadmin.core.model.bvo.*;
import com.baseweb.webadmin.core.model.pojo.*;
import com.baseweb.webadmin.core.util.*;
import com.baseweb.webadmin.service.ContentService;
import com.baseweb.webadmin.service.RoleService;
import com.baseweb.webadmin.service.UserOrderService;
import com.baseweb.webadmin.service.UserService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;

@Controller
@RequestMapping(value = "/user")
public class UserController extends BaseController {
    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    @Autowired
    private ContentService contentService;

    @Autowired
    private UserOrderService userOrderService;

    private String prefix = "/user";

    @RequestMapping(value = "/editUser")
    public String editUser(@RequestParam(value = "id", defaultValue = "") Integer userId,
                           Model model) {
        if (userId != null) {
            if (userId == 1) {
                return "/accessDenied";
            } else {
                User user = userService.selectUserById(userId);
                if (user == null) {
                    return prefix + "/editUser";
                }

                model.addAttribute("user", user);

                if (StringUtils.isNotBlank(user.getProvince())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getProvince()));
                }

                if (StringUtils.isNotBlank(user.getCity())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getCity()));
                }

                if (StringUtils.isNotBlank(user.getArea())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getArea()));
                }else{
                    model.addAttribute("area", "");
                }

                boolean is_biz = false;

                if ((user.getUserType().intValue() == RoleType.NORMAL_BIZ.getCode())
                        || (user.getUserType().intValue() == RoleType.TEAM_BIZ.getCode()))
                {
                    is_biz = true;
                }

                if (is_biz){
                    model.addAttribute("is_biz", is_biz);

                    List<ByChannelKeyword> byChannelKeywords = contentService.selectKeyWordListByPage(null, null, null,BaseState.NORMAL.getCode(), 0, Integer.MAX_VALUE);

                    model.addAttribute("byChannelKeywords", byChannelKeywords);

//                    List<Integer> keywordIds = new ArrayList<Integer>();
//                    if (byChannelKeywords != null && byChannelKeywords.size() > 0){
//                        for (ByChannelKeyword current : byChannelKeywords){
//                            keywordIds.add(current.getId());
//                        }
//                        model.addAttribute("byChannelKeywordIds", keywordIds);
//                    }
                }

                //没有角色的用户
                List<Role> list = roleService.selectRoleListByUser(userId.toString());
                if (list.size() == 0) {
                    return prefix + "/editUser";
                }
            }
        }

        model.addAttribute("userTypeList", UserType.getAllData());

        model.addAttribute("agentList", userService.selectUserByUserType(UserType.ADMIN.getCode(), BaseState.NORMAL.getCode()));

        List<ByChannel> channels = contentService.selectAllSubChannelList();

        model.addAttribute("workTypeList", channels);

        return prefix + "/editUser";
    }

    @RequestMapping(value = "/userManager", method = RequestMethod.GET)
    public String userManager(Model model) {
        model.addAttribute("roleList", getSubRoleOfCurrentUser());

        return prefix + "/userManager";
    }

    /**
     * 展示用户
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/viewUsers")
    public void viewUsers(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                          @RequestParam(value = "pageSize", defaultValue = "50", required = false) Integer pageSize,
                          @RequestParam(value = "cn_name", required = false) String cn_name,
                          @RequestParam(value = "username", required = false) String username,
                          @RequestParam(value = "province", required = false) String province,
                          @RequestParam(value = "city", required = false) String city,
                          @RequestParam(value = "status", required = false) Integer status,
                          @RequestParam(value = "roleName", required = false) String roleName,
                          @RequestParam(value = "searchType", required = false, defaultValue = "0") Integer searchType,
                          Model model) {
//        List<Role> roles = getSubRoleOfCurrentUser();
        Map map = new HashMap();
        map.put("cn_name", cn_name);
        map.put("username", username);
        map.put("province", CitiesUtil.CITIES_MAP.get(province));
        map.put("city", CitiesUtil.CITIES_MAP.get(city));
        map.put("status", status);

        map.put("searchType", searchType);
        map.put("roleName", roleName);

        List<UserVerifyBvo> verifyBvos = userService.selectBizVerifyStatusList(null, BaseState.NORMAL.getCode());
        Map<String, String> verifyMap = new HashMap<String, String>();
        if (verifyBvos != null && verifyBvos.size() > 0){
            for (UserVerifyBvo current : verifyBvos){
                verifyMap.put(""+current.getUserId(), current.getVerifyNameStr());
            }
        }

//        if (roles != null && roles.size() > 0) {
//            List<String> roleNames = new ArrayList<String>();
//            for (Role r : roles) {
//                roleNames.add(r.getRoleName());
//            }
//            map.put("roleNames", roleNames);
            map.put("roleNames", null);
            List<UserRoleBvo> userList = userService.selectUsersByPage(page, pageSize, map);
            if (userList != null && userList.size() > 0){
                for (UserRoleBvo current : userList){
                    current.setAuthStr(verifyMap.get(""+current.getUserId()));
                }
            }

            model.addAttribute("userRoleBvoList", userList);
            model.addAttribute("total", userService.getRowsByName(map));
//        } else {
//            model.addAttribute("userRoleBvoList", new ArrayList<UserRoleBvo>());
//            model.addAttribute("total", 0);
//        }
        model.addAttribute("page", page);
    }

    @RequestMapping(value = "/addDealCountView")
    public String addDealCountView(@RequestParam(value = "user_id",required = false) Integer user_id,
                           @RequestParam(value = "biz_deal_count",required = false) Integer biz_deal_count,
                           Model model) {
        if (user_id !=null && user_id > 0) {
            model.addAttribute("user_id", user_id);
        }

        if (biz_deal_count != null && biz_deal_count > 0){
            model.addAttribute("biz_deal_count", biz_deal_count);
        }else{
            model.addAttribute("biz_deal_count", 0);
        }

        return prefix + "/addDealCountView";
    }

    @RequestMapping(value = "/submitDealCount")
    public String submitDealCount(@RequestParam(value = "user_id",required = false) Integer user_id,
                           @RequestParam(value = "biz_deal_count",required = false) Integer biz_deal_count,
                           Model model) {
        if (user_id !=null && user_id > 0) {
            User user = userService.selectUserById(user_id);
            user.setBizDealCount(biz_deal_count);

            userService.updateUser(user);
        }

        return prefix + "/userManager";
    }

    /**
     * 跳转添加用户页面
     */
    @RequestMapping(value = "/addUserPage", method = RequestMethod.GET)
    public String addUserView(Model model) {
        List<Role> roleList = roleService.selectRoles();
        model.addAttribute("roleList", roleList);

        model.addAttribute("userTypeList", UserType.getAllData());

        List<ByChannel> channels = contentService.selectAllSubChannelList();

        model.addAttribute("workTypeList", channels);

        return prefix + "/addUser";
    }

//    /**
//     * 删除用户
//     *
//     * @param userId
//     * @return
//     */
//    @RequestMapping(value = "/deleteUser")
//    public String deleteUser(@RequestParam("userId") Integer userId, HttpServletRequest request) {
//        userService.deleteUserById(userId);
//        userService.deleteUserRoleByUserId(userId);
//        writeLog(request, "删除用户", "删除用户(id:" + userId + ")");
//        return "redirect:/user/viewUsers";
//    }


    /**
     * 判断用户是否存在
     *
     * @param userName
     * @param model
     * @return
     */
    @RequestMapping(value = "/isUser", method = RequestMethod.GET)
    public void isUser(@RequestParam("userName") String userName,
                       Model model,
                       HttpServletResponse response) {
        try {
            userName = URLDecoder.decode(userName, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        User user = userService.selectByName(userName);
        Boolean isUser = false;
        if (user != null) {
            isUser = true;
        }

        returnMsg(response, !isUser);
        return;
    }


    /**
     * 添加用户
     */
    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public void addUser(
            Model model, HttpServletRequest request,
            @RequestParam("userName") String userName,
            @RequestParam(value = "cnName", required = false) String cnName,
            @RequestParam(value = "trueName", required = false) String trueName,
            @RequestParam(value = "identity", required = false) String identity,
            @RequestParam(value = "user_type", required = false) Integer user_type,
            @RequestParam("password") String password,
            @RequestParam(value = "roleList", defaultValue = "") String roleList,
            @RequestParam(value = "status", defaultValue = "1") Integer status,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "descn", defaultValue = "") String descn,
            @RequestParam(value = "workTypeList", defaultValue = "") String workTypeList) throws IOException {
        if (StringUtils.isBlank(userName) || userService.selectByName(userName) != null) {
            model.addAttribute("success", false);
            return;
        }

        User user = new User();
        user.setUsername(userName.trim());
        user.setTrueName(trueName.trim());
        user.setIdentity(identity);
        user.setMobile(userName.trim());
        user.setPassword(MD5Util.Md5(password.trim()));
        user.setToken(MD5Util.Md5(user.getPassword()+"boyi"+ DateUtil.dateToString(new DateTime())+ RandCharUtil.getRandStr(8)));
        user.setCnName("user-"+RandCharUtil.getRandStr(8));
        user.setStatus(status);
        user.setUserType(user_type);
        user.setOrderCount(0);
        user.setCoins(50);
        user.setMoney(new BigDecimal("0.00"));
        user.setLevelCoins(0);
        user.setIsHot(0);

        if (StringUtils.isNotBlank(email)) {
            user.setEmail(email.trim());
        }

        if (StringUtils.isNotBlank(descn)) {
            user.setDescn(descn);
        }

        if (StringUtils.isNotBlank(cnName)) {
            user.setCnName(cnName);
        }

//        if (workTypeList.equalsIgnoreCase("-1")){
//            user.setBizWorkType(0);
//        }else{
            user.setBizWorkType(Integer.valueOf(workTypeList));
//        }

        userService.insertUser(user);

        writeCoinsLog(user, CoinType.REGISTER.getCode(),50);

        //add Role
        if (StringUtils.isNotBlank(roleList)) {
            User currentUser = userService.selectByName(userName);

            ObjectMapper mapper = new ObjectMapper();
            List<Map> value = mapper.readValue(roleList, ArrayList.class);
            for (Map m : value) {
                int roleId = (Integer) m.get("id");
                boolean checked = (Boolean) m.get("checked");
                UserRoleKey userRoleKey = new UserRoleKey();
                userRoleKey.setRoleId(roleId);
                userRoleKey.setUserId(currentUser.getId());
                if (checked) {
                    roleService.insertUserRoleKey(userRoleKey);
                } else {
                    roleService.deleteByPrimaryKey(userRoleKey);
                }
            }
        }

        model.addAttribute("success", true);
        writeLog(request, "添加用户", "添加用户(" + userName + ")");
        return;
    }

    /**
     * 添加用户
     */
    @RequestMapping(value = "/updateUser", method = RequestMethod.POST)
    public String updateUser(
            Model model, HttpServletRequest request,
            @RequestParam("id") Integer id,
            @RequestParam(value = "cnName", required = false) String cnName,
            @RequestParam(value = "trueName", required = false) String trueName,
            @RequestParam(value = "identity", required = false) String identity,
            @RequestParam(value = "user_type", required = false) Integer user_type,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "descn", required = false) String descn,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "area", required = false) String area,
            @RequestParam(value = "roleList", defaultValue = "") String roleList,
            @RequestParam(value = "biz_work_type", defaultValue = "") String biz_work_type,
            @RequestParam(value = "is_hot", defaultValue = "0") Integer is_hot,
            @RequestParam(value = "tag_ids", required = false) String tag_ids,
            @RequestParam(value = "biz_agent_id", required = false) Integer biz_agent_id) throws IOException {

        if (id == 1) {
            model.addAttribute("success", false);
            return prefix + "/userManager";
        }

        User user = userService.selectUserById(id);
        user.setCnName(cnName);
        user.setTrueName(trueName);
        user.setIdentity(identity);
        user.setUserType(user_type);
        user.setEmail(email);
        user.setDescn(descn);
        user.setIsHot(is_hot);

        user.setProvince(CitiesUtil.CITIES_MAP.get(province));
        user.setCity(CitiesUtil.CITIES_MAP.get(city));
        user.setArea(CitiesUtil.CITIES_MAP.get(area));

        if(biz_agent_id != null && biz_agent_id > 0){
            user.setBizAgentId(biz_agent_id);
        }

        if (StringUtils.isNotBlank(tag_ids)){
            user.setTagIds(tag_ids);
            List<ByChannelKeyword> byChannelKeywords = null;
            List<Integer> tagList = new ArrayList<Integer>();
            if (tag_ids.indexOf(",") != -1){
                String []tmpTag = tag_ids.split(",");
                for (int i = 0; i < tmpTag.length; i++) {
                    tagList.add(Integer.valueOf(tmpTag[i]));
                }
            }else{
                tagList.add(Integer.valueOf(tag_ids));
            }
            byChannelKeywords = contentService.findKeyWordList(tagList);

            StringBuffer tagSB = new StringBuffer();
            if (byChannelKeywords != null && byChannelKeywords.size() > 0){
                for (int i = 0; i < byChannelKeywords.size(); i++) {
                    if (i == 0){
                        tagSB.append(byChannelKeywords.get(i).getName());
                    }else{
                        tagSB.append(","+ byChannelKeywords.get(i).getName());
                    }
                }
                user.setTagNames(tagSB.toString());
            }

        }

//        if (StringUtils.isNotBlank(workTypeList)) {
//            ObjectMapper mapper = new ObjectMapper();
//            List<Map> value = mapper.readValue(workTypeList, ArrayList.class);
//            for (Map m : value) {
//                int roleId = (Integer) m.get("id");
//                boolean checked = (Boolean) m.get("checked");
//                UserRoleKey userRoleKey = new UserRoleKey();
//                userRoleKey.setRoleId(roleId);
//                userRoleKey.setUserId(user.getId());
//                if (checked) {
//                    roleService.insertUserRoleKey(userRoleKey);
//                } else {
//                    roleService.deleteByPrimaryKey(userRoleKey);
//                }
//            }
//        }

//        if (workTypeList.equalsIgnoreCase("-1")){
//            user.setBizWorkType(0);
//        }else{
            if(StringUtils.isNotBlank(biz_work_type)){
                user.setBizWorkType(Integer.valueOf(biz_work_type));
            }

//        }

        userService.updateByPrimaryKey(user);

        if (StringUtils.isNotBlank(roleList)) {
            ObjectMapper mapper = new ObjectMapper();
            List<Map> value = mapper.readValue(roleList, ArrayList.class);
            for (Map m : value) {
                int roleId = (Integer) m.get("id");
                boolean checked = (Boolean) m.get("checked");
                UserRoleKey userRoleKey = new UserRoleKey();
                userRoleKey.setRoleId(roleId);
                userRoleKey.setUserId(user.getId());
                if (checked) {
                    roleService.insertUserRoleKey(userRoleKey);
                } else {
                    roleService.deleteByPrimaryKey(userRoleKey);
                }
            }
        }

        model.addAttribute("success", true);
        writeLog(request, "编辑用户", "编辑用户(" + user.getUsername() + ")");
        return prefix + "/userManager";
    }

    /**
     * 查询数据权限
     * add by lxl
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/getRoleTree")
    public void getRoleTree(Model model,
                            @RequestParam(value = "id", defaultValue = "") Integer userId) {
        List<Role> roles = null;
        if (userId != null) {
            roles = roleService.selectRoleListByUser(userId.toString()); //获取被管理用户的直接角色
        }

        String userName = getUserName();
        if (userName != null) {
            User user = userService.selectByName(userName);
            if (user != null) {
                List<Role> list = roleService.selectRolesByUser(user.getId()); //获取当前用户的所有角色

                List<Role> directRoleList = roleService.selectRoleListByUser(user.getId().toString()); //获取当前用户的所有直接角色
                List<Integer> directRoleIdList = new ArrayList<Integer>();
                for (Role role : directRoleList) {
                    directRoleIdList.add(role.getId());
                }

                if (roles != null) {
                    List<Integer> roleIdList = new ArrayList<Integer>();
                    for (Role role : roles) {
                        roleIdList.add(role.getId());
                    }

                    //初始化勾选的角色
                    List<RoleTreeBvo> bvos = new ArrayList<RoleTreeBvo>();
                    for (Role role : list) {
                        RoleTreeBvo bvo = RoleTreeBvo.copyFromRole(role);
                        if (roleIdList.contains(role.getId())) {
                            bvo.setChecked(true);
                        } else {
                            bvo.setChecked(false);
                        }

//                        if (directRoleIdList.contains(role.getId())) {
//                            bvo.setNocheck(true);
//                        } else {
//                            bvo.setNocheck(false);
//                        }
                        bvo.setNocheck(false);
                        bvos.add(bvo);
                    }
                    model.addAttribute("list", bvos);
                    return;
                } else {
                    //初始化勾选的角色
                    List<RoleTreeBvo> bvos = new ArrayList<RoleTreeBvo>();
                    for (Role role : list) {
                        RoleTreeBvo bvo = RoleTreeBvo.copyFromRole(role);
//                        if (directRoleIdList.contains(role.getId())) {
//                            bvo.setNocheck(true);
//                        } else {
//                            bvo.setNocheck(false);
//                        }
                        bvo.setNocheck(false);
                        bvos.add(bvo);
                    }
                    model.addAttribute("list", bvos);
                    return;
                }
            }
        }
        return;
    }

    /**
     * 查询数据权限
     * add by lxl
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/getWorkTypeTree")
    public void getWorkTypeTree(Model model) {
        List<Role> roles = null;
        List<ByChannel> byChannels = contentService.selectChannelListByPage(null, null, BaseState.NORMAL.getCode(), 1, 1000);

        if (byChannels !=null && byChannels.size() > 0){
            List<WorkTypeTreeBvo> bvos = new ArrayList<WorkTypeTreeBvo>();

//            WorkTypeTreeBvo bvo = new WorkTypeTreeBvo();
//            bvo.setId(-1);
//            bvo.setParentId(0);
//            bvo.setRoleName("全选");
//            bvo.setNocheck(false);
//            bvos.add(bvo);

            for (ByChannel byChannel : byChannels) {
                WorkTypeTreeBvo currentBvo = WorkTypeTreeBvo.copyFromWorkType(byChannel);
                currentBvo.setNocheck(false);
                bvos.add(currentBvo);
            }
            model.addAttribute("list", bvos);
        }

        return;
    }

    /**
     * 展示权限(受限)
     */
    @RequestMapping(value = "/selectRoles")
    public String selectRoles(Model model) {
        model.addAttribute("roleList", getSubRoleOfCurrentUser());
        return prefix + "/viewRoles";
    }

    //获取当前用户所具有的子孙角色
    private List<Role> getSubRoleOfCurrentUser() {
        User user = userService.selectByName(getUserName());
        if (user == null) {
            return null;
        } else {
            List<Role> list = roleService.selectRolesByUser(user.getId()); //获取当前用户的所有角色
            List<Role> directRoleList = roleService.selectRoleListByUser(user.getId().toString()); //获取当前用户的所有直接角色

            for (Role role : directRoleList) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    Role r = list.get(i);
                    if (r != null && r.getId().equals(role.getId())) {
                        list.remove(i);
                    }
                }
            }

            return list;
        }
    }

    @RequestMapping(value = "/resetPassword")
    public void resetPassword(Model model,
                              @RequestParam(value = "id") Integer userId) {
        User user = userService.selectUserById(userId);
//        if (user != null && user.getUserType() == UserType.STANDARD.getTypeValue()) {
        if (user != null){
            String password = PasswordUtil.randomPassword();
            user.setPassword(MD5Util.Md5(password));
            userService.updateUser(user);
            model.addAttribute("msg", password);
//        } else if (user != null && user.getUserType() == UserType.LDAP.getTypeValue()) {
//            model.addAttribute("msg", "LDAP");
        }
        else {
            model.addAttribute("msg", "FAIL");
        }
        return;
    }

    @RequestMapping(value = "/password")
    public String userCenter(Model model) {
        return prefix + "/password";
    }

    /**
     * 修改密码
     *
     * @param model
     * @param request
     * @param oldPassword(经过md5加密)
     * @param newPassword(经过md5加密)
     */
    @RequestMapping(value = "/updatePassword")
    public void updatePassword(Model model, HttpServletRequest request,
                               @RequestParam("oldPassword") String oldPassword,
                               @RequestParam("newPassword") String newPassword) {
        String userName = getUserName();
        if (StringUtils.isBlank(userName)) {
            model.addAttribute("msg", SESSION_TIME_OUT);
            model.addAttribute("success", FAIL);
            return;
        }

        User user = userService.selectByName(userName);
        if (user == null) {
            model.addAttribute("msg", USER_NOT_EXIST);
            model.addAttribute("success", FAIL);
            return;
        } else {
            String msg;
            String success;
            if (!oldPassword.toLowerCase().equals(user.getPassword())) {
                msg = "原始密码错误";
                success = FAIL;
            } else {
                try {
                    user.setPassword(newPassword);
                    userService.updateUser(user);
                    msg = "更新密码成功！";
                    success = SUCCESS;
                } catch (Exception e) {
                    msg = "更新密码失败！";
                    success = FAIL;
                }
            }

            writeLog(request, "修改密码", "用户" + userName + msg);
            model.addAttribute("msg", msg);
            model.addAttribute("success", success);
            return;
        }
    }

    @RequestMapping(value = "/setStatus")
    public void setStatus(Model model, HttpServletRequest request,
                          @RequestParam(value = "id") Integer userId) {
        User user = userService.selectUserById(userId);
        if (user != null) {
            if (user.getStatus() == 1) {
                user.setStatus(-1);
            } else {
                user.setStatus(1);
            }

            int re = userService.updateUser(user);
            if (re > 0) {
                model.addAttribute("msg", SUCCESS);
            } else {
                model.addAttribute("msg", FAIL);
            }
        } else {
            model.addAttribute("msg", USER_NOT_EXIST);
            return;
        }

        return;
    }


    //认证
    @RequestMapping(value = "/verifyManage")
    public String verifyManage(Model model) {

        model.addAttribute("authTypeList", AuthType.getAllData());

//        List<UserVerifyBvo> verifyBvos = userService.selectBizVerifyStatusList(null, BaseState.NORMAL.getCode());
//        Map<String, String> verifyMap = new HashMap<String, String>();
//        if (verifyBvos != null && verifyBvos.size() > 0){
//            for (UserVerifyBvo current : verifyBvos){
//                verifyMap.put(""+current.getUserId(), current.getVerifyNameStr());
//            }
//        }

//        model.addAttribute("verifyMap", verifyMap);
        return prefix + "/verifyManage";
    }

    @RequestMapping(value = "/getVerifyList")
    public void getVerifyList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 @RequestParam(value = "user_id", required = false) Integer user_id,
                                 @RequestParam(value = "auth_type", required = false) Integer auth_type,
                                 @RequestParam(value = "status", required = false) Integer status,
                                 @RequestParam(value = "name", required = false) String name,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<UserVerifyBvo> verifyBvos = userService.selectBizVerifyStatusList(null, BaseState.NORMAL.getCode());
        Map<String, String> verifyMap = new HashMap<String, String>();
        if (verifyBvos != null && verifyBvos.size() > 0){
            for (UserVerifyBvo current : verifyBvos){
                verifyMap.put(""+current.getUserId(), current.getVerifyNameStr());
            }
        }

        List<ByUserBizAuthBvo> list = new ArrayList<ByUserBizAuthBvo>();
        List<ByUserBizAuth> byUserBizAuths = userService.selectBizVerifyListByPage(user_id, auth_type, name,(page-1)*pageSize, pageSize, status);
        int total = userService.selectBizVerifyListCount(user_id, auth_type, name, status);

//        List<Integer> userIds = null;
        if (byUserBizAuths != null && byUserBizAuths.size() > 0) {
//            userIds = new ArrayList<Integer>();
            for (ByUserBizAuth current : byUserBizAuths) {
//                userIds.add(current.getUserId());
                User user = userService.selectUserById(current.getUserId());
                ByChannel channel = null;
                if (user != null){
                    channel = contentService.findChannel(user.getBizWorkType());
                }
                ByUserBizAuthBvo byUserBizAuthBvo = ByUserBizAuthBvo.copyFrom(current, UserInfoBvo.copyFrom(user, null, channel), verifyMap.get(""+user.getId()));
                list.add(byUserBizAuthBvo);
            }
        }



        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/myVerify")
    public String myVerify() {
        return prefix + "/myVerify";
    }

    @RequestMapping(value = "/getMyVerifyList")
    public void getMyCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 @RequestParam(value = "auth_type", required = false) Integer auth_type,
                                 @RequestParam(value = "name", required = false) String name,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserBizAuth> list = userService.selectBizVerifyListByPage(user.getId(), auth_type, name,(page-1)*pageSize, pageSize);
        int total = userService.selectBizVerifyListCount(user.getId(), auth_type, name);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/addVerifyView")
    public String addVerifyView(@RequestParam(value = "id",required = false) Integer id,
                                 Model model) {

        User user = getCurrentUser();
        List<Integer> userIds = new ArrayList<Integer>();
        userIds.add(user.getId());

        List<UserVerifyBvo> verifyBvos = userService.selectBizVerifyStatusList(userIds, BaseState.NORMAL.getCode());
        if (verifyBvos != null && verifyBvos.size() > 0){
            model.addAttribute("authTypeList", AuthType.getUnAuthData(verifyBvos.get(0).getVerifyStr()));
        }else {
            model.addAttribute("authTypeList", AuthType.getAllData());
        }
        List<ByChannel> channels = contentService.selectAllSubChannelList();

        model.addAttribute("workTypeList", channels);

        boolean is_writable = true;

        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        return prefix + "/addVerifyView";
    }

    @RequestMapping(value = "/editVerifyView")
    public String editVerifyView(@RequestParam(value = "id",required = false) Integer id,
                                 Model model) {

        if (id != null && id > 0){
            model.addAttribute("bizVerify", userService.findBizVerify(id));
        }

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        model.addAttribute("authTypeList", AuthType.getAllData());

        return prefix + "/editVerifyView";
    }

    @RequestMapping(value = "/passVerifyView")
    public void passVerifyView(@RequestParam(value = "id",required = true) Integer id,
                                 @RequestParam(value = "status",defaultValue = "1") Integer status,
                                 Model model) {

        if (id != null && id > 0){
            ByUserBizAuth byUserBizAuth = userService.findBizVerify(id);
            byUserBizAuth.setStatus(status);

            userService.insertBizVerify(byUserBizAuth);

            if (byUserBizAuth.getAuthType().intValue() == AuthType.BIZ_AUTH.getCode()) {
                User user = userService.selectUserById(byUserBizAuth.getUserId());
                if (user != null) {
                    UserRoleKey userRoleKey = new UserRoleKey();
                    userRoleKey.setRoleId(user.getUserType());
                    userRoleKey.setUserId(byUserBizAuth.getUserId());
                    roleService.insertUserRoleKey(userRoleKey);
//                user.setUserType(UserType.NORMAL_BIZ.getCode());
//                userService.updateUser(user);
                }
            }

            User user = userService.selectUserById(byUserBizAuth.getUserId());
            if (user != null) {
                user.setCoins(user.getCoins() + Constants.COINS_VERIFY_GIFT);
                userService.updateUser(user);

                writeCoinsLog(user, CoinType.VERIFY.getCode(), Constants.COINS_VERIFY_GIFT);

                if (StringUtils.isNotBlank(user.getMobile())){
                    //send msg
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("code", AuthType.getNameByCode(byUserBizAuth.getAuthType()).getName());

                    CommonUtil.sendMessage(user.getMobile(), JSONObject
                            .fromObject(map).toString(), ConfigUtil
                            .getSms_template_code_verified());
                }
            }
            model.addAttribute("msg", SUCCESS);
            return;
        }
            model.addAttribute("msg", FAIL);
        return;
//        return prefix + "/verifyManage";
    }

    @RequestMapping(value = "/rejectVerifyView")
    public String rejectVerifyView(@RequestParam(value = "id",required = true) Integer id,
                                   @RequestParam(value = "status",defaultValue = "2") Integer status,
                           Model model) {
        model.addAttribute("id", id);
        model.addAttribute("status", status);

        return prefix + "/rejectVerifyView";
    }

    @RequestMapping(value = "/submitRejectVerify")
    public String submitRejectVerify(@RequestParam(value = "id",required = false) Integer id,
                                     @RequestParam(value = "status",defaultValue = "2") Integer status,
                                   @RequestParam(value = "descn",required = false) String descn,
                                   Model model) {
        if (id !=null && id > 0) {
            ByUserBizAuth byUserBizAuth = userService.findBizVerify(id);
            byUserBizAuth.setStatus(status);
            byUserBizAuth.setDescn(descn);
            userService.insertBizVerify(byUserBizAuth);

            User user = userService.selectUserById(byUserBizAuth.getUserId());
            if (user != null && StringUtils.isNotBlank(user.getMobile())){
                //send msg
                Map<String, Object> map = new LinkedHashMap<String, Object>();
                map.put("code", AuthType.getNameByCode(byUserBizAuth.getAuthType()).getName());

                CommonUtil.sendMessage(user.getMobile(), JSONObject
                        .fromObject(map).toString(), ConfigUtil
                        .getSms_template_code_unverified());
            }
        }

        return prefix + "/verifyManage";
    }

    @RequestMapping(value = "/submitVerify")
    public String submitVerify(@RequestParam(value = "id",required = false) Integer id,
                             @RequestParam(value = "user_id",required = false) Integer user_id,
                             @RequestParam(value = "file",required = false) MultipartFile file,
                             @RequestParam(value = "name",required = false) String name,
                             @RequestParam(value = "descn",required = false) String descn,
                             @RequestParam(value = "auth_type",required = false) Integer auth_type,
                             @RequestParam(value = "work_type",required = false) Integer work_type,
                             @RequestParam(value = "status",defaultValue = "-1") Integer status,
                             Model model) {

        User user = getCurrentUser();
        try{
            ByUserBizAuth byUserBizAuth = null;
            if (id != null && id > 0){
                byUserBizAuth = userService.findBizVerify(id);
            }else{
                byUserBizAuth = new ByUserBizAuth();
            }

            byUserBizAuth.setUserId(user.getId());
            byUserBizAuth.setName(name);
            byUserBizAuth.setDescn(descn);
            byUserBizAuth.setStatus(status);
            byUserBizAuth.setAuthType(auth_type);
            byUserBizAuth.setCreateTime(new DateTime());
            byUserBizAuth.setUpdateTime(new DateTime());

            if (file != null && file.getSize() > 0){
                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+".jpg";

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
                UploadUtil.uploadData(file.getBytes(), img_url);
                byUserBizAuth.setImgUrl(img_url);
            }

            userService.insertBizVerify(byUserBizAuth);

            //add work_type
            if (work_type != null && work_type > 0) {
//                User user = getCurrentUser();
                user.setBizWorkType(work_type);
                userService.updateUser(user);
            }
            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        return prefix + "/myVerify";
    }

    //后台管理人员自动认证
    @RequestMapping(value = "/addAutoVerifyView")
    public String addAutoVerifyView(@RequestParam(value = "id",required = false) Integer id,
                                    @RequestParam(value = "user_id",required = false) Integer user_id,
                                Model model) {

        User user = getCurrentUser();
        List<Integer> userIds = new ArrayList<Integer>();
        userIds.add(user_id);

        List<UserVerifyBvo> verifyBvos = userService.selectBizVerifyStatusList(userIds, BaseState.NORMAL.getCode());
        if (verifyBvos != null && verifyBvos.size() > 0){
            model.addAttribute("authTypeList", AuthType.getUnAuthData(verifyBvos.get(0).getVerifyStr()));
        }else {
            model.addAttribute("authTypeList", AuthType.getAllData());
        }

        List<ByChannel> channels = contentService.selectAllSubChannelList();

        model.addAttribute("workTypeList", channels);

        boolean is_writable = true;

        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        model.addAttribute("user_id", user_id);
        return prefix + "/addAutoVerifyView";
    }

    @RequestMapping(value = "/submitAutoVerify")
    public String submitAutoVerify(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "user_id",required = false) Integer user_id,
                               @RequestParam(value = "file",required = false) MultipartFile file,
                               @RequestParam(value = "name",required = false) String name,
                               @RequestParam(value = "descn",required = false) String descn,
                               @RequestParam(value = "auth_type",required = false) Integer auth_type,
                               @RequestParam(value = "work_type",required = false) Integer work_type,
                               @RequestParam(value = "status",defaultValue = "1") Integer status,
                               Model model) {
        try{
            ByUserBizAuth byUserBizAuth = null;
            if (id != null && id > 0){
                byUserBizAuth = userService.findBizVerify(id);
            }else{
                byUserBizAuth = new ByUserBizAuth();
            }

            byUserBizAuth.setUserId(user_id);
            byUserBizAuth.setName(name);
            byUserBizAuth.setDescn(descn);
            byUserBizAuth.setStatus(status);
            byUserBizAuth.setAuthType(auth_type);
            byUserBizAuth.setCreateTime(new DateTime());
            byUserBizAuth.setUpdateTime(new DateTime());

            if (file != null && file.getSize() > 0){
                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+".jpg";

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
                UploadUtil.uploadData(file.getBytes(), img_url);
                byUserBizAuth.setImgUrl(img_url);
            }

            userService.insertBizVerify(byUserBizAuth);

            //add work_type
            if (work_type != null && work_type > 0) {
                User user = userService.selectUserById(user_id);
                user.setBizWorkType(work_type);
                userService.updateUser(user);
            }
            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        return prefix + "/userManager";
    }


    //开通城市
    @RequestMapping(value = "/openManage")
    public String openManage() {
        return prefix + "/openManage";
    }

    @RequestMapping(value = "/getOpenCityList")
    public void getMyCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 @RequestParam(value = "user_id", required = false) Integer user_id,
                                 @RequestParam(value = "province", required = false) String province,
                                 @RequestParam(value = "open_type", required = false) Integer open_type,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByOpenCity> list = userService.selectOpenCityListByPage(user_id, open_type, province,(page-1)*pageSize, pageSize);
        int total = userService.selectOpenCityListCount(user_id, open_type, province);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/openConfigManage")
    public String openConfigManage() {
        return prefix + "/openConfigManage";
    }

    @RequestMapping(value = "/getOpenConfigList")
    public void getOpenConfigList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                  @RequestParam(value = "province", required = false) String province,
                                  @RequestParam(value = "open_type", required = false) Integer open_type,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByOpenCity> list = userService.selectOpenCityListByPage(user.getId(), open_type, province,(page-1)*pageSize, pageSize);
        int total = userService.selectOpenCityListCount(user.getId(), open_type, province);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/addOpenCityView")
    public String addOpenCityView(@RequestParam(value = "id",required = false) Integer id,
                                Model model) {

        model.addAttribute("openTypeList", OpenType.getAllData());

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        return prefix + "/addOpenCityView";
    }

    @RequestMapping(value = "/editOpenCityView")
    public String editOpenCityView(@RequestParam(value = "id",required = false) Integer id,
                                 Model model) {

        model.addAttribute("openTypeList", OpenType.getAllData());

        if (id != null && id > 0){
            model.addAttribute("openCity", userService.findOpenCity(id));
        }

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        return prefix + "/editOpenCityView";
    }

    @RequestMapping(value = "/submitOpenCity")
    public String submitOpenCity(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "user_id",required = false) Integer user_id,
                               @RequestParam(value = "province",required = true) String province,
                               @RequestParam(value = "city",required = false) String city,
                               @RequestParam(value = "area",required = false) String area,
                               @RequestParam(value = "open_type",required = false) Integer open_type,
                               @RequestParam(value = "status",defaultValue = "1") Integer status,
                               Model model) {
        try{
            if (StringUtils.isBlank(province)){
                model.addAttribute("result", "省份不能为空!");
                return prefix + "/openConfigManage";
            }

            if (CitiesUtil.SPECIAL_CITIES.contains(CitiesUtil.CITIES_MAP.get(province))){
                if (StringUtils.isBlank(city)){
                    List<String> areas = CitiesUtil.getAreasListByCityName(CitiesUtil.CITIES_MAP.get(province));
                    for (String current : areas) {
                        writeOpenCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(province), current, status, open_type);
                    }
                }else{
                    writeOpenCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(area), status, open_type);
                }
            }else {

                if (StringUtils.isBlank(city)) {
                    List<String> cities = CitiesUtil.getCitiesListByProvinceName(province);
                    for (String current : cities) {
                        List<String> areas = CitiesUtil.getAreasListByCityName(current);
                        for (String currentArea : areas) {
                            writeOpenCity(CitiesUtil.CITIES_MAP.get(province), current, currentArea, status, open_type);
                        }
                    }
                } else {
                    if (StringUtils.isBlank(area)) {
                        List<String> areas = CitiesUtil.getAreasListByCityName(city);
                        for (String current : areas) {
                            writeOpenCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(city), current, status, open_type);
                        }
                    } else {
                        writeOpenCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(city), CitiesUtil.CITIES_MAP.get(area), status, open_type);
                    }
                }
            }
//            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
//            model.addAttribute("result", false);
        }
        return prefix + "/openConfigManage";
    }

    @RequestMapping(value = "/deleteOpenCity")
    public String deleteOpenCity(@RequestParam(value = "id",required = true) Integer id,
                                 Model model) {
        try{
            if (id != null && id > 0){
                userService.deleteOpenCity(id);
                model.addAttribute("result", "删除成功!");
            }else{
                model.addAttribute("result", "编号不能为空!");
            }
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", "删除失败!");
        }
        return prefix + "/openConfigManage";
    }


    //购物车
    @RequestMapping(value = "/trolleyManage")
    public String trolleyManage(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        model.addAttribute("user",user);
        model.addAttribute("username", user.getUsername());

        List<ByChannel> topList = contentService.selectChannelListByPage(ChannelType.TOP_CHANNEL.getCode(), 0, BaseState.NORMAL.getCode(), 0, 6);
        model.addAttribute("topList", topList);

        List<ByUserTrolley> byUserTrolleys = userService.selectTrolleyListByPage(user.getId(), (page-1)*pageSize, pageSize);
        int total = userService.selectTrolleyListCount(user.getId());

        List<ByUserTrolleyBvo> list = new ArrayList<ByUserTrolleyBvo>();
        if (byUserTrolleys !=null && byUserTrolleys.size() > 0){
            for (ByUserTrolley current : byUserTrolleys){
                ByUserTrolleyBvo bvo = ByUserTrolleyBvo.copyFromByUserTrolley(current);
                bvo.setProduct(userService.findBizProduct(bvo.getProductId()));
                bvo.setUser(userService.selectUserById(bvo.getProduct().getUserId()));

                list.add(bvo);
            }
        }

        model.addAttribute("trolleyList", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
        return prefix + "/trolleyManage";
    }

    @RequestMapping(value = "/addTrolley")
    public String addTrolley(@RequestParam(value = "product_id",required = false) Integer product_id,
                             @RequestParam(value = "biz_user_id",required = false) Integer biz_user_id,
                             @RequestParam(value = "schedule_date",required = false) String schedule_date,
                             @RequestParam(value = "dinner_type",required = false) String dinner_type,
                             @RequestParam(value = "descn",required = false) String descn,
                             @RequestParam(value = "qty_item_1",defaultValue = "1") Integer qty_item_1,
                                Model model) {
//        UserForm userForm = new UserForm();
//        model.addAttribute("userForm", userForm);
//        model.addAttribute("misName", misName);

        User user = getCurrentUser();

//        if (biz_user_id == null || biz_user_id < 1 || (biz_user_id.intValue() == user.getId().intValue())){
//            return "";
//        }

        if (product_id != null && product_id > 0) {
            ByUserTrolley byUserTrolley = new ByUserTrolley();
            byUserTrolley.setProductId(product_id);
            byUserTrolley.setUserId(user.getId());
            if (product_id != null && product_id.intValue() > 0){
                if (biz_user_id != null && biz_user_id.intValue() > 0){
                    byUserTrolley.setBizUserId(biz_user_id);
                }else{
                    byUserTrolley.setBizUserId(userService.findBizProduct(product_id).getUserId());
                }
            }
            byUserTrolley.setScheduleDate(DateUtil.getDateTime(schedule_date));
            byUserTrolley.setDinnerType(dinner_type);
            byUserTrolley.setDescn(descn);

            if(qty_item_1 == null || qty_item_1 < 1){
                qty_item_1 = 1;
            }

            byUserTrolley.setAmount(qty_item_1);
            byUserTrolley.setCreateTime(new DateTime());
            byUserTrolley.setUpdateTime(new DateTime());

            userService.insertTrolley(byUserTrolley);

        }
        return "redirect:"+prefix + "/trolleyManage";
    }

    @RequestMapping(value = "/deleteTrolley")
    public String deleteTrolley(@RequestParam(value = "trolley_id",required = false) Integer trolley_id,
                                Model model) {

        userService.deleteTrolley(trolley_id);

        return "redirect:"+prefix + "/trolleyManage";
    }





    //Invite
    @RequestMapping(value = "/addInviteView")
    public String addInviteView(@RequestParam(value = "id",required = false) Integer id,
                                Model model) {

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        return prefix + "/addInviteView";
    }

    @RequestMapping(value = "/editInviteView")
    public String editInviteView(@RequestParam(value = "id",required = false) Integer id,
                                 Model model) {

        if (id != null && id > 0){
            model.addAttribute("invite", userService.findInvite(id));
        }

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        return prefix + "/editInviteView";
    }

    @RequestMapping(value = "/submitInvite")
    public String submitInvite(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "user_id",required = false) Integer user_id,
                               @RequestParam(value = "invite_by",required = false) Integer invite_by,
                               @RequestParam(value = "status",defaultValue = "-1") Integer status,
                               Model model) {
        try{
            ByUserInvite byUserInvite = null;
            if (id != null && id > 0){
                byUserInvite = userService.findInvite(id);
            }else{
                byUserInvite = new ByUserInvite();
            }

//            User user = getCurrentUser();
            byUserInvite.setUserId(user_id);
            byUserInvite.setInviteBy(invite_by);
            byUserInvite.setStatus(status);
            byUserInvite.setCreateTime(new DateTime());
            byUserInvite.setUpdateTime(new DateTime());

            userService.insertInvite(byUserInvite);
            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        return prefix + "/inviteManage";
    }

    @RequestMapping(value = "/inviteManage")
    public String inviteManage() {
        return prefix + "/inviteManage";
    }

    @RequestMapping(value = "/getInviteList")
    public void getInviteList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 @RequestParam(value = "user_id", required = false) Integer user_id,
                                 @RequestParam(value = "invite_by", required = false) Integer invite_by,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByUserInvite> list = userService.selectInviteListByPage(user_id, invite_by,(page-1)*pageSize, pageSize);
        int total = userService.selectInviteListCount(user_id, invite_by);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/myInviteManage")
    public String myInviteManage() {
        return prefix + "/myInviteManage";
    }

    @RequestMapping(value = "/getMyInviteList")
    public void getMyInviteList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                              @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                              @RequestParam(value = "user_id", required = false) Integer user_id,
                              Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserInvite> list = userService.selectInviteListByPage(user_id, user.getId(),(page-1)*pageSize, pageSize);
        int total = userService.selectInviteListCount(user_id, user.getId());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    //修改我的资料
    @RequestMapping(value = "/editMyUser")
    public String editMyUser(Model model) {
        User user = getCurrentUser();
        if (user != null &&  user.getId() != null) {
//            if (user.getId() == 1) {
//                return "/accessDenied";
//            } else {
//                if (user == null) {
//                    return prefix + "/editMyUser";
//                }

                model.addAttribute("user", user);

                if (StringUtils.isNotBlank(user.getProvince())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getProvince()));
                }

                if (StringUtils.isNotBlank(user.getCity())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getCity()));
                }

                if (StringUtils.isNotBlank(user.getArea())){
                    model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getArea()));
                }else{
                    model.addAttribute("area", "");
                }

                //没有角色的用户
                List<Role> list = roleService.selectRoleListByUser(user.getId().toString());
                if (list.size() == 0) {
                    return prefix + "/editMyUser";
                }
//            }
        }

        boolean is_biz = false;

        if ((user.getUserType().intValue() == RoleType.NORMAL_BIZ.getCode())
                || (user.getUserType().intValue() == RoleType.TEAM_BIZ.getCode()))
        {
            is_biz = true;
        }

        if (is_biz){
            model.addAttribute("is_biz", is_biz);
        }

        return prefix + "/editMyUser";
    }
    @RequestMapping(value = "/updateMyUser", method = RequestMethod.POST)
    public String updateMyUser(
            Model model, HttpServletRequest request,
            @RequestParam(value = "cnName", required = false) String cnName,
            @RequestParam(value = "trueName", required = false) String trueName,
            @RequestParam(value = "identity", required = false) String identity,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "descn", required = false) String descn,
            @RequestParam(value = "remote_fee", required = false) String remote_fee,

            @RequestParam(value = "file", required = false) MultipartFile file,
            @RequestParam(value = "province", required = false) String province,
            @RequestParam(value = "city", required = false) String city,
            @RequestParam(value = "area", required = false) String area,
            @RequestParam(value = "address", required = false) String address,

            @RequestParam(value = "height", required = false) String height,
            @RequestParam(value = "weight", required = false) String weight,
            @RequestParam(value = "domain", required = false) String domain,
            @RequestParam(value = "wechat", required = false) String wechat,
            @RequestParam(value = "qq", required = false) String qq,
            @RequestParam(value = "style_type", required = false) String style_type,
            @RequestParam(value = "biz_price", required = false) String biz_price
            ) throws IOException {

        User user = getCurrentUser();
//        if (user.getId() == 1) {
//            model.addAttribute("success", false);
//            return "/accessDenied";
//        }

        user.setCnName(cnName);
        user.setTrueName(trueName);
        user.setIdentity(identity);
        user.setEmail(email);
        user.setDescn(descn);
        user.setRemoteFee(remote_fee);

        user.setProvince(CitiesUtil.CITIES_MAP.get(province));
        user.setCity(CitiesUtil.CITIES_MAP.get(city));
        user.setArea(CitiesUtil.CITIES_MAP.get(area));

        user.setAddress(address);

        user.setHeight(height);
        user.setWeight(weight);
        user.setDomain(domain);
        user.setWechat(wechat);
        user.setQq(qq);

        if (StringUtils.isNotBlank(style_type)) {
            user.setBizStyle(style_type);
        }

        if (StringUtils.isNotBlank(biz_price)) {
            user.setBizPrice(ObjectFormatter.str2BigDecimal(biz_price));
        }

        if (file != null && file.getSize() > 0){
            String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+".jpg";

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
            UploadUtil.uploadData(file.getBytes(), img_url);
            user.setAvatar(img_url);
        }

        userService.updateByPrimaryKey(user);
//        if (StringUtils.isNotBlank(roleList)) {
//            ObjectMapper mapper = new ObjectMapper();
//            List<Map> value = mapper.readValue(roleList, ArrayList.class);
//            for (Map m : value) {
//                int roleId = (Integer) m.get("id");
//                boolean checked = (Boolean) m.get("checked");
//                UserRoleKey userRoleKey = new UserRoleKey();
//                userRoleKey.setRoleId(roleId);
//                userRoleKey.setUserId(user.getId());
//                if (checked) {
//                    roleService.insertUserRoleKey(userRoleKey);
//                } else {
//                    roleService.deleteByPrimaryKey(userRoleKey);
//                }
//            }
//        }

        model.addAttribute("user", user);
        if (StringUtils.isNotBlank(user.getProvince())){
            model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getProvince()));
        }

        if (StringUtils.isNotBlank(user.getCity())){
            model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getCity()));
        }

        if (StringUtils.isNotBlank(user.getArea())){
            model.addAttribute("area", CitiesUtil.CITIES_CODE_MAP.get(user.getArea()));
        }else{
            model.addAttribute("area", "");
        }
        model.addAttribute("result", "修改成功!");
        writeLog(request, "编辑用户", "编辑用户(" + user.getUsername() + ")");
        return prefix + "/editMyUser";
    }

    //婚期及预算
    @RequestMapping(value = "/budgetManage")
    public String budgetManage() {
        return prefix + "/budgetManage";
    }

    @RequestMapping(value = "/getBudgetList")
    public void getInviteList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                              @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                              @RequestParam(value = "user_id", required = false) Integer user_id,
                              Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByUserWedBudget> list = userService.selectBudgetListByPage(user_id, (page-1)*pageSize, pageSize);
        int total = userService.selectBudgetListCount(user_id);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/myBudgetManage")
    public String myBudgetManage() {
        return prefix + "/myBudgetManage";
    }

    @RequestMapping(value = "/getMyBudgetList")
    public void getMyInviteList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserWedBudget> list = userService.selectBudgetListByPage(user.getId(), (page-1)*pageSize, pageSize);
        int total = userService.selectBudgetListCount(user.getId());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    //作品
    @RequestMapping(value = "/addExampleView")
    public String addExampleView(@RequestParam(value = "id",required = false) Integer id,
                                 @RequestParam(value = "example_type",required = false) Integer example_type,
                                Model model) {

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        model.addAttribute("example_type", example_type);

        return prefix + "/addExampleView";
    }

    @RequestMapping(value = "/editExampleView")
    public String editExampleView(@RequestParam(value = "id",required = false) Integer id,
                                  @RequestParam(value = "example_type",required = false) Integer example_type,
                                 Model model) {

        if (id != null && id > 0){
            model.addAttribute("example", userService.findExample(id));
        }

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        model.addAttribute("example_type", example_type);

        return prefix + "/editExampleView";
    }

    @RequestMapping(value = "/setExampleCover")
    public String setExampleCover(@RequestParam(value = "id",required = false) Integer id,
                                  Model model) {

        if (id != null && id > 0){
            ByUserExample byUserExample = userService.findExample(id);

            User user = getCurrentUser();

            user.setBizCover(byUserExample.getImgUrl());

            userService.updateUser(user);
        }

        return prefix + "/myExampleManage";
    }

    @RequestMapping(value = "/deleteExample")
    public String deleteExample(@RequestParam(value = "id",required = true) Integer id,
                                @RequestParam(value = "example_type",required = false) Integer example_type,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                 Model model) {
        try{
            if (id != null && id > 0){
                userService.deleteExample(id);
                model.addAttribute("result", "删除成功!");
            }else{
                model.addAttribute("result", "编号不能为空!");
            }
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", "删除失败!");
        }

        String pathUrl = request.getHeader("referer");
        if (StringUtils.isNotBlank(pathUrl) && pathUrl.indexOf("exampleManage") != -1){
            return prefix + "/exampleManage";
        }else {
            if (example_type.intValue() == ExampleType.ALBUM.getCode()) {
                return prefix + "/myExampleManage";
            } else if (example_type.intValue() == ExampleType.VIDEO.getCode()) {
                return prefix + "/exampleVideoManage";
            } else {
                return prefix + "/examplePageManage";
            }
        }
    }

    @RequestMapping(value = "/passExampleView")
    public String passExampleView(@RequestParam(value = "id",required = true) Integer id,
                                 @RequestParam(value = "status",defaultValue = "1") Integer status,
                                 Model model) {

        if (id != null && id > 0){
            ByUserExample byUserExample = userService.findExample(id);
            byUserExample.setStatus(status);

            userService.insertExample(byUserExample);
        }

        return prefix + "/exampleManage";
    }

    @RequestMapping(value = "/submitExample")
    public String submitInvite(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "user_id",required = false) Integer user_id,
                               @RequestParam(value = "order_id",required = false) Integer order_id,
                               @RequestParam(value = "order_detail_id",required = false) Integer order_detail_id,
                               @RequestParam(value = "file",required = false) MultipartFile file,
                               @RequestParam(value = "file1",required = false) MultipartFile file1,
                               @RequestParam(value = "file2",required = false) MultipartFile file2,
                               @RequestParam(value = "file3",required = false) MultipartFile file3,
                               @RequestParam(value = "file4",required = false) MultipartFile file4,
                               @RequestParam(value = "file5",required = false) MultipartFile file5,
                               @RequestParam(value = "name",required = false) String name,
                               @RequestParam(value = "descn",required = false) String descn,
                               @RequestParam(value = "status",defaultValue = "-1") Integer status,
                               @RequestParam(value = "example_type",required = false) Integer example_type,
                               @RequestParam(value = "case_time",required = false) String case_time,
                               @RequestParam(value = "case_hotel",required = false) String case_hotel,
                               @RequestParam(value = "case_comment",required = false) String case_comment,
                               @RequestParam(value = "case_detail",required = false) String case_detail,
                               Model model) {
        try{
            ByUserExample byUserExample = null;
            if (id != null && id > 0){
                byUserExample = userService.findExample(id);
            }else{
                byUserExample = new ByUserExample();
            }

            User user = getCurrentUser();
            byUserExample.setUserId(user.getId());
            byUserExample.setName(name);
            byUserExample.setDescn(descn);
            byUserExample.setOrderId(order_id);
            byUserExample.setExampleType(example_type);
            byUserExample.setOrderDetailId(order_detail_id);
            byUserExample.setStatus(BaseState.DELETE.getCode());
            byUserExample.setCreateTime(new DateTime());
            byUserExample.setUpdateTime(new DateTime());

            if (example_type.intValue() == ExampleType.CASE.getCode()){
                byUserExample.setCaseTime(case_time);
                byUserExample.setCaseHotel(case_hotel);
                byUserExample.setCaseComment(case_comment);
                byUserExample.setCaseDetail(case_detail);
            }

            if (file != null && file.getSize() > 0){
                if(file.getSize()>10000000)
                {
                    throw new Exception("上传失败：文件大小不能超过10M");
                }

                String fileName = file.getOriginalFilename();
                int  indexdot =  fileName.lastIndexOf(".");
                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+fileName.substring(indexdot);

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
                UploadUtil.uploadData(file.getBytes(), img_url);
                byUserExample.setImgUrl(img_url);
            }

            userService.insertExample(byUserExample);

            if (example_type.intValue() == ExampleType.CASE.getCode()){
                ByUserExampleDetail byUserExampleDetail = new ByUserExampleDetail();
                byUserExampleDetail.setUserId(user.getId());
                byUserExampleDetail.setName(name);
                byUserExampleDetail.setExampleId(byUserExample.getId());
                byUserExampleDetail.setStatus(status);
                byUserExampleDetail.setCreateTime(new DateTime());
                byUserExampleDetail.setUpdateTime(new DateTime());

                List<MultipartFile> files = new ArrayList<MultipartFile>();
                if (file != null && file.getSize() > 0){
                    files.add(file);
                }

                if (file1 != null && file1.getSize() > 0){
                    files.add(file1);
                }

                if (file2 != null && file2.getSize() > 0){
                    files.add(file2);
                }

                if (file3 != null && file3.getSize() > 0){
                    files.add(file3);
                }

                if (file4 != null && file4.getSize() > 0){
                    files.add(file4);
                }

                if (file5 != null && file5.getSize() > 0){
                    files.add(file5);
                }

                for (MultipartFile current : files) {
                    if (current != null && current.getSize() > 0){
                        String fileName = current.getOriginalFilename();
                        int  indexdot =  fileName.lastIndexOf(".");
                        String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(current.getOriginalFilename()))+fileName.substring(indexdot);

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
                        UploadUtil.uploadData(current.getBytes(), img_url);
                        byUserExampleDetail.setImgUrl(img_url);
                    }

                    userService.insertExampleDetail(byUserExampleDetail);
                }
            }

            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }

        if (example_type.intValue() == ExampleType.ALBUM.getCode()){
            return prefix + "/myExampleManage";
        }else if (example_type.intValue() == ExampleType.VIDEO.getCode()){
            return prefix + "/exampleVideoManage";
        }else{
            return prefix + "/examplePageManage";
        }
    }
    @RequestMapping(value = "/exampleManage")
    public String exampleManage(@RequestParam(value = "user_id", required = false) Integer user_id,
                                Model model) {

        model.addAttribute("user_id", user_id);

        return prefix + "/exampleManage";
    }

    @RequestMapping(value = "/getExampleList")
    public void getExampleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                              @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                              @RequestParam(value = "user_id", required = false) Integer user_id,
                              @RequestParam(value = "status", required = false) Integer status,
                              Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByUserExampleBvo> list = new ArrayList<ByUserExampleBvo>();
        List<ByUserExample> byUserExamples = userService.selectExampleListByPage(user_id, status, null, (page-1)*pageSize, pageSize);
        if (byUserExamples != null && byUserExamples.size() > 0){
            for(ByUserExample current : byUserExamples){
                User currentUser = userService.selectUserById(current.getUserId());

                list.add(ByUserExampleBvo.copyFrom(current, UserInfoBvo.copyFrom(currentUser, null, contentService.findChannel(currentUser.getBizWorkType()))));
            }
        }

        int total = userService.selectExampleListCount(user_id,status, null);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/myExampleManage")
    public String myExampleManage() {
        return prefix + "/myExampleManage";
    }

    @RequestMapping(value = "/getMyExampleList")
    public void getMyExampleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserExample> list = userService.selectExampleListByPage(user.getId(), null, ExampleType.ALBUM.getCode(), (page-1)*pageSize, pageSize);

        int total = userService.selectExampleListCount(user.getId(), null, ExampleType.ALBUM.getCode());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    //作品详情
    @RequestMapping(value = "/addExampleDetailView")
    public String addExampleDetailView(@RequestParam(value = "id",required = false) Integer id,
                                       @RequestParam(value = "example_id",required = false) Integer example_id,
                                 Model model) {

        model.addAttribute("example_id", example_id);

        return prefix + "/addExampleDetailView";
    }


    @RequestMapping(value = "/setExampleDetailCover")
    public String setExampleDetailCover(@RequestParam(value = "id",required = false) Integer id,
                                        @RequestParam(value = "example_id",required = false) Integer example_id,
                                  Model model) {

        if (id != null && id > 0){
            ByUserExampleDetail byUserExampleDetail = userService.findExampleDetail(id);

            User user = getCurrentUser();

            user.setBizCover(byUserExampleDetail.getImgUrl());

            userService.updateUser(user);
        }

        model.addAttribute("example_id", example_id);
        return prefix + "/myExampleDetailManage";
    }

    @RequestMapping(value = "/deleteExampleDetail")
    public String deleteExampleDetail(@RequestParam(value = "id",required = true) Integer id,
                                      @RequestParam(value = "example_id",required = false) Integer example_id,
                                Model model) {
        try{
            if (id != null && id > 0){
                userService.deleteExampleDetail(id);
                model.addAttribute("result", "删除成功!");
            }else{
                model.addAttribute("result", "编号不能为空!");
            }
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", "删除失败!");
        }

        model.addAttribute("example_id", example_id);
        return prefix + "/myExampleDetailManage";
    }

    @RequestMapping(value = "/submitExampleDetail")
    public String submitExampleDetail(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "example_id",required = false) Integer example_id,
                               @RequestParam(value = "file",required = false) MultipartFile file,
                              @RequestParam(value = "file1",required = false) MultipartFile file1,
                              @RequestParam(value = "file2",required = false) MultipartFile file2,
                              @RequestParam(value = "file3",required = false) MultipartFile file3,
                              @RequestParam(value = "file4",required = false) MultipartFile file4,
                               @RequestParam(value = "name",required = false) String name,
                               @RequestParam(value = "status",defaultValue = "1") Integer status,
                               Model model) {
        try{
            ByUserExampleDetail byUserExampleDetail = null;
            if (id != null && id > 0){
                byUserExampleDetail = userService.findExampleDetail(id);
            }else{
                byUserExampleDetail = new ByUserExampleDetail();
            }

            User user = getCurrentUser();
            byUserExampleDetail.setUserId(user.getId());
            byUserExampleDetail.setName(name);
            byUserExampleDetail.setExampleId(example_id);
            byUserExampleDetail.setStatus(status);
            byUserExampleDetail.setCreateTime(new DateTime());
            byUserExampleDetail.setUpdateTime(new DateTime());

            List<MultipartFile> files = new ArrayList<MultipartFile>();
            if (file != null && file.getSize() > 0){
                files.add(file);
            }

            if (file1 != null && file1.getSize() > 0){
                files.add(file1);
            }

            if (file2 != null && file2.getSize() > 0){
                files.add(file2);
            }

            if (file3 != null && file3.getSize() > 0){
                files.add(file3);
            }

            if (file4 != null && file4.getSize() > 0){
                files.add(file4);
            }

            for (MultipartFile current : files) {
                if (current != null && current.getSize() > 0){
                    String fileName = current.getOriginalFilename();
                    int  indexdot =  fileName.lastIndexOf(".");
                    String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(current.getOriginalFilename()))+fileName.substring(indexdot);

//                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
                    UploadUtil.uploadData(current.getBytes(), img_url);
                    byUserExampleDetail.setImgUrl(img_url);
                }

                userService.insertExampleDetail(byUserExampleDetail);
            }

            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        model.addAttribute("example_id", example_id);
        return prefix + "/myExampleDetailManage";
    }

    @RequestMapping(value = "/myExampleDetailManage")
    public String myExampleDetailManage(@RequestParam(value = "example_id", required = false) Integer example_id,
                                      Model model) {

        model.addAttribute("example_id", example_id);

        return prefix + "/myExampleDetailManage";
    }

    @RequestMapping(value = "/getMyExampleDetailList")
    public void getMyExampleDetailList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                     @RequestParam(value = "example_id", required = false) Integer example_id,
                                     Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserExampleDetail> list = userService.selectExampleDetailListByPage(user.getId(), example_id, null, (page-1)*pageSize, pageSize);
        int total = userService.selectExampleDetailListCount(example_id, user.getId(),null);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/exampleDetailManage")
    public String exampleDetailManage(@RequestParam(value = "example_id", required = false) Integer example_id,
                                @RequestParam(value = "user_id", required = false) Integer user_id,
                                Model model) {

        model.addAttribute("example_id", example_id);
        model.addAttribute("user_id", user_id);

        return prefix + "/exampleDetailManage";
    }

    @RequestMapping(value = "/getExampleDetailList")
    public void getExampleDetailList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                               @RequestParam(value = "user_id", required = false) Integer user_id,
                               @RequestParam(value = "example_id", required = false) Integer example_id,
                               Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

//        List<ByUserExampleBvo> list = new ArrayList<ByUserExampleBvo>();
//        List<ByUserExample> byUserExamples = userService.selectExampleListByPage(user_id, null, (page-1)*pageSize, pageSize);
//        if (byUserExamples != null && byUserExamples.size() > 0){
//            for(ByUserExample current : byUserExamples){
//                User currentUser = userService.selectUserById(current.getUserId());
//
//                list.add(ByUserExampleBvo.copyFrom(current, UserInfoBvo.copyFrom(currentUser, null, contentService.findChannel(currentUser.getBizWorkType()))));
//            }
//        }

        List<ByUserExampleDetail> list = userService.selectExampleDetailListByPage(user_id, example_id, null, (page-1)*pageSize, pageSize);
        int total = userService.selectExampleDetailListCount(example_id, user_id,null);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }



    //video
    @RequestMapping(value = "/exampleVideoManage")
    public String exampleVideoManage() {
        return prefix + "/exampleVideoManage";
    }

    @RequestMapping(value = "/getExampleVideoList")
    public void getExampleVideoList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserExample> list = userService.selectExampleListByPage(user.getId(), null, ExampleType.VIDEO.getCode(), (page-1)*pageSize, pageSize);

        int total = userService.selectExampleListCount(user.getId(), null, ExampleType.VIDEO.getCode());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

//    @RequestMapping(value = "/addExampleVideoView")
//    public String addExampleVideoView(@RequestParam(value = "id",required = false) Integer id,
//                                 Model model) {
//
//        boolean is_writable = true;
//
//        User user = getCurrentUser();
//        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());
//
//        for(Role current : userRoles) {
//            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
//                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
//            {
//                is_writable = false;
//                break;
//            }
//        }
//
//        if (is_writable){
//            model.addAttribute("is_writable", is_writable);
//        }
//
//        return prefix + "/addExampleVideoView";
//    }
//
//    @RequestMapping(value = "/deleteExampleVideo")
//    public String deleteExampleVideo(@RequestParam(value = "id",required = true) Integer id,
//                                Model model) {
//        try{
//            if (id != null && id > 0){
//                userService.deleteExample(id);
//                model.addAttribute("result", "删除成功!");
//            }else{
//                model.addAttribute("result", "编号不能为空!");
//            }
//        }catch (Exception ex){
//            ex.printStackTrace();
//            model.addAttribute("result", "删除失败!");
//        }
//        return prefix + "/exampleVideoManage";
//    }
//
//    @RequestMapping(value = "/submitExampleVideo")
//    public String submitExampleVideo(@RequestParam(value = "id",required = false) Integer id,
//                               @RequestParam(value = "user_id",required = false) Integer user_id,
//                               @RequestParam(value = "order_id",required = false) Integer order_id,
//                               @RequestParam(value = "order_detail_id",required = false) Integer order_detail_id,
//                               @RequestParam(value = "file",required = false) MultipartFile file,
//                               @RequestParam(value = "name",required = false) String name,
//                               @RequestParam(value = "descn",required = false) String descn,
//                               @RequestParam(value = "status",defaultValue = "-1") Integer status,
//                               Model model) {
//        try{
//            ByUserExample byUserExample = null;
//            if (id != null && id > 0){
//                byUserExample = userService.findExample(id);
//            }else{
//                byUserExample = new ByUserExample();
//            }
//
//            User user = getCurrentUser();
//            byUserExample.setUserId(user.getId());
//            byUserExample.setName(name);
//            byUserExample.setDescn(descn);
//            byUserExample.setOrderId(order_id);
//            byUserExample.setOrderDetailId(order_detail_id);
//            byUserExample.setStatus(status);
//            byUserExample.setCreateTime(new DateTime());
//            byUserExample.setUpdateTime(new DateTime());
//
//            if (file != null && file.getSize() > 0){
//                String fileName = file.getOriginalFilename();
//                int  indexdot =  fileName.lastIndexOf(".");
//                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+fileName.substring(indexdot);
//
////                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
//                UploadUtil.uploadData(file.getBytes(), img_url);
//                byUserExample.setImgUrl(img_url);
//            }
//
//            userService.insertExample(byUserExample);
//            model.addAttribute("result", true);
//        }catch (Exception ex){
//            ex.printStackTrace();
//            model.addAttribute("result", false);
//        }
//        return prefix + "/exampleVideoManage";
//    }



    //example page
    @RequestMapping(value = "/examplePageManage")
    public String examplePageManage() {
        return prefix + "/examplePageManage";
    }

    @RequestMapping(value = "/getExamplePageList")
    public void getExamplePageList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                    @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                    Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserExample> list = userService.selectExampleListByPage(user.getId(), null, ExampleType.CASE.getCode(), (page-1)*pageSize, pageSize);

        int total = userService.selectExampleListCount(user.getId(), null, ExampleType.CASE.getCode());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

//    @RequestMapping(value = "/addExamplePageView")
//    public String addExamplePageView(@RequestParam(value = "id",required = false) Integer id,
//                                      Model model) {
//
//        boolean is_writable = true;
//
//        User user = getCurrentUser();
//        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());
//
//        for(Role current : userRoles) {
//            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
//                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
//            {
//                is_writable = false;
//                break;
//            }
//        }
//
//        if (is_writable){
//            model.addAttribute("is_writable", is_writable);
//        }
//
//        return prefix + "/addExamplePageView";
//    }
//
//    @RequestMapping(value = "/deleteExamplePage")
//    public String deleteExamplePage(@RequestParam(value = "id",required = true) Integer id,
//                                     Model model) {
//        try{
//            if (id != null && id > 0){
//                userService.deleteExample(id);
//                model.addAttribute("result", "删除成功!");
//            }else{
//                model.addAttribute("result", "编号不能为空!");
//            }
//        }catch (Exception ex){
//            ex.printStackTrace();
//            model.addAttribute("result", "删除失败!");
//        }
//        return prefix + "/examplePageManage";
//    }
//
//    @RequestMapping(value = "/submitExamplePage")
//    public String submitExamplePage(@RequestParam(value = "id",required = false) Integer id,
//                                     @RequestParam(value = "user_id",required = false) Integer user_id,
//                                     @RequestParam(value = "order_id",required = false) Integer order_id,
//                                     @RequestParam(value = "order_detail_id",required = false) Integer order_detail_id,
//                                     @RequestParam(value = "file",required = false) MultipartFile file,
//                                     @RequestParam(value = "name",required = false) String name,
//                                     @RequestParam(value = "descn",required = false) String descn,
//                                     @RequestParam(value = "status",defaultValue = "-1") Integer status,
//                                     Model model) {
//        try{
//            ByUserExample byUserExample = null;
//            if (id != null && id > 0){
//                byUserExample = userService.findExample(id);
//            }else{
//                byUserExample = new ByUserExample();
//            }
//
//            User user = getCurrentUser();
//            byUserExample.setUserId(user.getId());
//            byUserExample.setName(name);
//            byUserExample.setDescn(descn);
//            byUserExample.setOrderId(order_id);
//            byUserExample.setOrderDetailId(order_detail_id);
//            byUserExample.setStatus(status);
//            byUserExample.setCreateTime(new DateTime());
//            byUserExample.setUpdateTime(new DateTime());
//
//            if (file != null && file.getSize() > 0){
//                String fileName = file.getOriginalFilename();
//                int  indexdot =  fileName.lastIndexOf(".");
//                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+fileName.substring(indexdot);
//
////                FileUtil.saveFile(file.getInputStream(), PropertiesConfig.getProperty("img_upload_path", "/home")+"/"+img_url);
//                UploadUtil.uploadData(file.getBytes(), img_url);
//                byUserExample.setImgUrl(img_url);
//            }
//
//            userService.insertExample(byUserExample);
//            model.addAttribute("result", true);
//        }catch (Exception ex){
//            ex.printStackTrace();
//            model.addAttribute("result", false);
//        }
//        return prefix + "/examplePageManage";
//    }















    //user recommend
    @RequestMapping(value = "/recommendManage")
    public String recommendManage(@RequestParam(value = "example_id", required = false) Integer example_id,
                                  Model model) {

        model.addAttribute("example_id", example_id);

        return prefix + "/recommendManage";
    }

    @RequestMapping(value = "/getRecommendUserList")
    public void getRecommendUserList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                     @RequestParam(value = "example_id", required = false) Integer example_id,
                                     Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserRecommendBvo> list = new ArrayList<ByUserRecommendBvo>();
        List<ByUserRecommend> byUserRecommends = userService.selectRecommendUserListByPage(user.getId(), null, example_id, (page-1)*pageSize, pageSize);

        if (byUserRecommends != null && byUserRecommends.size() > 0){
            for (ByUserRecommend current : byUserRecommends){
                User recommendUser = userService.selectUserById(current.getRecommendId());
                UserInfoBvo recommendUserBvo = UserInfoBvo.copyFrom(recommendUser, null, contentService.findChannel(recommendUser.getBizWorkType()));
                list.add(ByUserRecommendBvo.copyFrom(current, userService.selectUserById(current.getUserId()),
                        recommendUserBvo, userService.findExample(current.getExampleId())));
            }
        }

        int total = userService.selectRecommendUserListCount(user.getId(), null, example_id);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/addUserRecommendView")
    public String addUserRecommendView(@RequestParam(value = "id",required = false) Integer id,
                                       @RequestParam(value = "example_id", required = false) Integer example_id,
                                      Model model) {

        boolean is_writable = true;

        User user = getCurrentUser();
        List<Role> userRoles = roleService.selectRoleListByUser(user.getId().toString());

        for(Role current : userRoles) {
            if ((current.getId().intValue() == RoleType.NORMAL_BIZ.getCode())
                    || (current.getId().intValue() == RoleType.NORMAL_USER.getCode()))
            {
                is_writable = false;
                break;
            }
        }

        if (is_writable){
            model.addAttribute("is_writable", is_writable);
        }

        model.addAttribute("example_id", example_id);
        return prefix + "/addUserRecommendView";
    }

    @RequestMapping(value = "/deleteRecommendUser")
    public String deleteRecommendUser(@RequestParam(value = "id",required = true) Integer id,
                                      @RequestParam(value = "example_id", required = false) Integer example_id,
                                     Model model) {
        try{
            if (id != null && id > 0){
                userService.deleteRecommendUser(id);
                model.addAttribute("result", "删除成功!");
            }else{
                model.addAttribute("result", "编号不能为空!");
            }
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", "删除失败!");
        }

        if (example_id != null && example_id > 0){
            return prefix + "/examplePageManage";
        }else {
            return prefix + "/recommendManage";
        }
    }

    @RequestMapping(value = "/submitRecommendUser")
    public String submitRecommendUser(@RequestParam(value = "id",required = false) Integer id,
                                     @RequestParam(value = "user_id",required = false) Integer user_id,
                                     @RequestParam(value = "recommend_id",required = false) Integer recommend_id,
                                     @RequestParam(value = "example_id",required = false) Integer example_id,
                                     @RequestParam(value = "sort",required = false) Integer sort,
                                     @RequestParam(value = "status",defaultValue = "1") Integer status,
                                     Model model) {
        try{
            ByUserRecommend byUserRecommend = null;
            if (id != null && id > 0){
                byUserRecommend = userService.findRecommendUser(id);
            }else{
                byUserRecommend = new ByUserRecommend();
            }

            User user = getCurrentUser();
            byUserRecommend.setUserId(user.getId());
            byUserRecommend.setRecommendId(recommend_id);
            byUserRecommend.setExampleId(example_id);
            byUserRecommend.setSort(sort);
            byUserRecommend.setStatus(status);
            byUserRecommend.setCreateTime(new DateTime());
            byUserRecommend.setUpdateTime(new DateTime());

            userService.insertRecommendUser(byUserRecommend);
            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }

        if (example_id != null && example_id > 0){
            return prefix + "/examplePageManage";
        }else{
            return prefix + "/recommendManage";
        }

    }



















    @RequestMapping(value = "/submitBizRegisterDetail")
    public String submitBizRegister(@RequestParam(value = "avatar", required = true) MultipartFile avatar,
                                    @RequestParam(value = "file", required = true) MultipartFile file,
                                    @RequestParam(value = "cn_name",required = true) String cn_name,
                                    @RequestParam(value = "user_type",required = true) Integer user_type,
                                    @RequestParam(value = "biz_work_type",required = true) Integer biz_work_type,
                                    Model model) {

        try {
            User user = getCurrentUser();

            if (user == null){
                return "/accessDenied";
            }

            user.setCnName(cn_name);
            user.setUserType(user_type);
            user.setBizWorkType(biz_work_type);
            user.setBizDealCount(0);
            user.setOrderCount(0);

            if (avatar != null && avatar.getSize() > 0){
                String avatar_img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+".jpg";

                UploadUtil.uploadData(avatar.getBytes(), avatar_img_url);

                user.setAvatar(avatar_img_url);
            }


            userService.updateUser(user);

            //新增认证信息
            ByUserBizAuth byUserBizAuth = new ByUserBizAuth();
            byUserBizAuth.setUserId(user.getId());
            byUserBizAuth.setName("认证材料");
            byUserBizAuth.setDescn("认证材料");
            byUserBizAuth.setStatus(BaseState.DELETE.getCode());
            byUserBizAuth.setAuthType(AuthType.BIZ_AUTH.getCode());
            byUserBizAuth.setCreateTime(new DateTime());
            byUserBizAuth.setUpdateTime(new DateTime());

            if (file != null && file.getSize() > 0){
                String img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8) + MD5Util.Md5(file.getOriginalFilename()))+".jpg";

                UploadUtil.uploadData(file.getBytes(), img_url);
                byUserBizAuth.setImgUrl(img_url);
            }

            userService.insertBizVerify(byUserBizAuth);

            model.addAttribute("username", user.getUsername());
            model.addAttribute("user", user);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "/right";
    }

    //代理加盟
    @RequestMapping(value = "/agentCityManage")
    public String agentCityManage() {
        return prefix + "/agentCityManage";
    }

    @RequestMapping(value = "/getAgentCityList")
    public void getAgentCityList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                  @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 @RequestParam(value = "user_id",required = false) Integer user_id,
                                  Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByUserBizAgentCityBvo> list = new ArrayList<ByUserBizAgentCityBvo>();
        List<ByUserBizAgentCity> bizAgentCities = userService.selectAgentCityListByPage(user_id,(page-1)*pageSize, pageSize);
        if (bizAgentCities != null && bizAgentCities.size() > 0){
            for(ByUserBizAgentCity current : bizAgentCities){
                ByUserBizAgentCityBvo bvo = ByUserBizAgentCityBvo.copyFrom(current, userService.selectUserById(current.getUserId()));
                list.add(bvo);
            }
        }


        int total = userService.selectAgentCityListCount(user_id);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/addAgentCityView")
    public String addAgentCityView(@RequestParam(value = "id",required = false) Integer id,
                                  Model model) {

        List<User> userList = userService.selectUserListByTypeAndPage(UserType.ADMIN.getCode(), 0, Integer.MAX_VALUE);
        model.addAttribute("agentList", userList);

        return prefix + "/addAgentCityView";
    }

    @RequestMapping(value = "/submitAgentCity")
    public String submitAgentCity(@RequestParam(value = "id",required = false) Integer id,
                                 @RequestParam(value = "user_id",required = false) Integer user_id,
                                 @RequestParam(value = "province",required = true) String province,
                                 @RequestParam(value = "city",required = false) String city,
                                 Model model) {
        try{
            if (StringUtils.isBlank(province)){
                model.addAttribute("result", "省份不能为空!");
                return prefix + "/agentCityManage";
            }

            if (CitiesUtil.SPECIAL_CITIES.contains(CitiesUtil.CITIES_MAP.get(province))){
                if (StringUtils.isBlank(city)){
                    List<String> areas = CitiesUtil.getAreasListByCityName(CitiesUtil.CITIES_MAP.get(province));
                    for (String current : areas) {
                        writeAgentCity(CitiesUtil.CITIES_MAP.get(province), current, user_id);
                    }
                }else{
                    writeAgentCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(city), user_id);
                }
            }else {
                if (StringUtils.isBlank(city)) {
                    List<String> cities = CitiesUtil.getCitiesListByProvinceName(province);
                    for (String current : cities) {
                        writeAgentCity(CitiesUtil.CITIES_MAP.get(province), current, user_id);
                    }
                } else {
                    writeAgentCity(CitiesUtil.CITIES_MAP.get(province), CitiesUtil.CITIES_MAP.get(city), user_id);
                }
            }
//            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
//            model.addAttribute("result", false);
        }
        return prefix + "/agentCityManage";
    }

    @RequestMapping(value = "/deleteAgentCity")
    public String deleteAgentCity(@RequestParam(value = "id",required = true) Integer id,
                                 Model model) {
        try{
            if (id != null && id > 0){
                userService.deleteAgentCity(id);
                model.addAttribute("result", "删除成功!");
            }else{
                model.addAttribute("result", "编号不能为空!");
            }
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", "删除失败!");
        }
        return prefix + "/agentCityManage";
    }




    @RequestMapping(value = "/addBizInfoView")
    public String addBizInfoView(Model model) {
        User user = getCurrentUser();

        model.addAttribute("user", user);

        List<ByChannel> channels = contentService.selectAllSubChannelList();

        model.addAttribute("workTypeList", channels);

        return prefix + "/addBizInfoView";
    }

    @RequestMapping(value = "/feedback")
    public String feedback(Model model) {
        UserForm userForm = new UserForm();
        model.addAttribute("userForm", userForm);
//        model.addAttribute("misName", misName);
        return prefix + "/feedback";
    }

    @RequestMapping(value = "/confirm_order")
    public String confirm_order(@RequestParam(value = "product_id",required = false) Integer product_id,
                              @RequestParam(value = "biz_user_id",required = false) Integer biz_user_id,
                              @RequestParam(value = "buy_type",required = false) Integer buy_type,
                            Model model) {

        User user = userService.selectUserById(biz_user_id);
        model.addAttribute("user", user);

        model.addAttribute("buy_type", buy_type);

        ByUserBizProduct product = userService.findBizProduct(product_id);
        model.addAttribute("product", product);
        model.addAttribute("deposit", product.getCurrentPrice().multiply(Constants.PRODUCT_DEPOSIT_RATIO));

        List<ByChannel> topList = contentService.selectChannelListByPage(ChannelType.TOP_CHANNEL.getCode(), 0, BaseState.NORMAL.getCode(), 0, 6);
        model.addAttribute("topList", topList);

        Map<String, String> scheduleData = userOrderService.getUserScheduleListView(biz_user_id, 0, 0);

        if (scheduleData != null && scheduleData.keySet().size() > 0) {
            try {
                model.addAttribute("scheduleData", new ObjectMapper().writeValueAsString(scheduleData));
            } catch (IOException e) {
                model.addAttribute("scheduleData", "");
                e.printStackTrace();
            }
        }else{
            model.addAttribute("scheduleData", "");
        }

        return prefix + "/confirm_order";
    }

    @RequestMapping(value = "/pay_order")
    public String pay_order(Model model) {
        UserForm userForm = new UserForm();
//        model.addAttribute("userForm", userForm);
//        model.addAttribute("misName", misName);

        List<ByChannel> topList = contentService.selectChannelListByPage(ChannelType.TOP_CHANNEL.getCode(), 0, BaseState.NORMAL.getCode(), 0, 6);
        model.addAttribute("topList", topList);

        return prefix + "/pay_order";
    }

    @RequestMapping(value = "/order_detail")
    public String order_detail(Model model) {
        UserForm userForm = new UserForm();
        model.addAttribute("userForm", userForm);
//        model.addAttribute("misName", misName);
        return prefix + "/order_detail";
    }
}
